package com.pdg.mcplugin.invisiblehand.commandprocessors;

import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import com.pdg.mcplugin.common.ArgumentList;

public class Utilities {

	public static String getWorldIfPlayer(CommandSender theCommandSender) {
		if(isPlayer(theCommandSender)){
			Player thePlayer = (Player)theCommandSender;
			return thePlayer.getWorld().getName();
		}
		return null;
	}

	public static boolean checkArgumentCount(CommandSender theCommandSender,
			String theWorldName, ArgumentList theArgumentList, int theArgumentCount,
			String theMessage) {
		if(theWorldName!=null){
			if(theArgumentList.size()<theArgumentCount){
				theCommandSender.sendMessage(theMessage);
				return false;
			}
		}else{
			if(theArgumentList.size()<(theArgumentCount+1)){
				theCommandSender.sendMessage(theMessage);
				return false;
			}
		}
		return true;
	}

	public static String getWorldName(ArgumentList theArgumentList) {
		String theWorldName = null;
		while(!theArgumentList.isEmpty()){
			if(theWorldName==null){
				theWorldName = theArgumentList.pop();
			}else{
				theWorldName+=" ";
				theWorldName += theArgumentList.pop();
				
			}
		}
		return theWorldName;
	}
	
	public static boolean isPlayer(CommandSender theCommandSender){
		return theCommandSender instanceof Player;
	}
}
